import tkinter
import ClassLib
class App:
    def __init__(self):
        self.root = tkinter.Tk()
        self.root.title("课程展示")
        self.root.geometry("550x600")
        self.label = tkinter.Label(self.root, text="付老师课堂")
        self.label.grid(row=0, column=0, columnspan=8)
        self.button1 = tkinter.Button(self.root, text="上课",
                                      command=self.class_start,
                                      width=7, height=1)
        self.button1.grid(row=1, column=0)
        self.button2 = tkinter.Button(self.root, text="下课",
                                      command=self.class_end,
                                      width=7, height=1)
        self.button2.grid(row=1, column=7)
        self.create_lecture_buttons()
        self.photo = None  # 用于存储图像对象
        # 初始化摄像头相关实例变量
        self.is_camera_on = False
        self.cap = None
        self.photo = None  # 添加实例变量用于保存PhotoImage对象

    def class_start(self):
        self.label.config(text="大数据班上课")

    def class_end(self):
        self.label.config(text="大数据班下课")

    def create_lecture_buttons(self):
        for i in range(1, 33):
            row = (i - 1) // 8 + 2
            # 计算行号，从第3行开始，每8个按钮换一行
            col = (i - 1) % 8
            button = tkinter.Button(self.root, text=f"讲课{i}",
                                    command=lambda num=i:
                                    self.lecture(num),
                                    width=7, height=1)
            button.grid(row=row, column=col, padx=5, pady=5)

    def lecture(self, i):
        if i == 1:
            ClassLib.draw_shape1()
        if i == 2:
            ClassLib.draw_shape2()
        if i == 3:
            ClassLib.draw_Heart1()
        if i == 4:
            ClassLib.WordCloudTest(self)
            # 传递self.root作为参数
        if i == 5:
            ClassLib.tkwindows1()
        if i == 6:
            ClassLib.tkwindows2(self)
        if i == 7:
            ClassLib.connect_mysql1()
        if i == 8:
            ClassLib.connect_mysql2()
        if i == 14:
            ClassLib.start_camera()
        if i == 15:
            ClassLib.video_to_face(self)
        self.label.config(text=f"正在讲课{i}")
    # 加载人脸和眼睛的级联分类器

if __name__ == "__main__":
    app = App()
    app.root.mainloop()